/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SparqlQuery;

/**
 *
 * @author antonio
 */
public class DbpediaQueryFactory {
    
    public void setIntLevel(int intLevel)
    {
        this.intLevel = intLevel;
    }
    
    private int intLevel;
    private String resource;
    private String stringLevel;
    
    /***************************************************************************
     * questi sono i valori di LEVEL che bisogn passare a createQuery()        *
     **************************************************************************/
    
    private static String comune = "COMUNE";
    private static String provincia = "PROVINCIA";
    private static String regione = "REGIONE";
    
    public void setStringLevel()
    {
        // todo: e fai uno switvh invece che sta schifezza!!!
        if(this.intLevel == 0)
            this.stringLevel = comune;
        else
            if(this.intLevel == 1)
                this.stringLevel = provincia;
            else
                if(this.intLevel == 2)
                     this.stringLevel = regione;
    }
    
    public String getStringLevel()
    {
        return this.stringLevel;
    }
    
    public void setResource(String resource)
    {
        this.resource = resource;
    }
    
    public String getResource()
    {
        return this.resource;
    }
    
   
   
       
        
    public String createQuery(String resource)
    {
        
        this.setStringLevel();
        this.setResource(resource);
        
        if(this.stringLevel.equals(comune))
        {
        /***************************************************************************
        * seleziono tutti i comuni di una provincia e i loro rispettivi abstract  *
        **************************************************************************/
    
            String queryComune = "PREFIX dbpedia2: <http://dbpedia.org/property/> " +
            "PREFIX : <http://dbpedia.org/resource/> " +
            "SELECT ?comune ?abstract WHERE" +
            "{ ?comune dbpedia2:province :" + "Province_of_" + this.resource + " ." +
            "?comune dbpedia2:abstract ?abstract . " +
                    "FILTER ( lang(?abstract) = 'it' ) }";
            
            return queryComune;
        }
        else
            if(this.stringLevel.equals(provincia))
            {
        /***************************************************************************
        * seleziono l'abstract di una provincia                                   *
        **************************************************************************/
    
            String queryProvinacia = "PREFIX dbpedia2: <http://dbpedia.org/property/> " +
            "PREFIX : <http://dbpedia.org/resource/> " +
            "SELECT ?abstract WHERE" +
            "{ :" + this.resource + " dbpedia2:abstract ?abstract ." +
                    "FILTER ( lang(?abstract) = 'it' ) }";

            return queryProvinacia;
           }
            else
            {
            /***************************************************************************
            *seleziono l'abstract di una regione                                      *  
            **************************************************************************/
    
            String queryRegione = "PREFIX dbpedia2: <http://dbpedia.org/property/> " +
            "PREFIX : <http://dbpedia.org/resource/> " +
            "SELECT ?abstract WHERE" +
            "{ :" + this.resource + " dbpedia2:abstract ?abstract ." +
                    "FILTER ( lang(?abstract) = 'it' ) }";

                //if(this.level.equals(regione))
                    return queryRegione;
            }
    }
     
}
